package uniandes.dermatologia;

import uniandes.dermatologia.models.PhysicalExamination.Distribution;
import uniandes.dermatologia.singleton.DermatologiaUniandesApp;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.support.v4.app.NavUtils;

public class DistributionActivity extends Activity {

	private RadioGroup groupActivity;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_distribution);

		getActionBar().setDisplayHomeAsUpEnabled(false);

		groupActivity = (RadioGroup) findViewById(R.id.radioGroupDistribution);

		Button btnBack = (Button) findViewById(R.id.btnBackDistribution);
		Button btnNext = (Button) findViewById(R.id.btnNextDistribution);

		Typeface font = Typeface.createFromAsset(getAssets(),
				"fonts/Roboto-Light.ttf");

		btnBack.setTypeface(font);
		btnNext.setTypeface(font);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.distribution, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void onClickNext(View v) {

		if (groupActivity.getCheckedRadioButtonId() == R.id.radioSymmetricalDistribution) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setDistribution(Distribution.symmetrical);
		} else if (groupActivity.getCheckedRadioButtonId() == R.id.radioAsymmetricalDistribution) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setDistribution(Distribution.asymmetrical);
		} else if (groupActivity.getCheckedRadioButtonId() == R.id.radioConfluentDistribution) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setDistribution(Distribution.confluent);
		} else if (groupActivity.getCheckedRadioButtonId() == R.id.radioScatteredDistribution) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setDistribution(Distribution.scattered);
		} else if (groupActivity.getCheckedRadioButtonId() == R.id.radioOtherDistribution) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setDistribution(Distribution.other);
		}

		Intent intent = new Intent(this, BodyActivity.class);
		startActivity(intent);
	}

	public void onClickBack(View v) {
		finish();
	}
}
